import Request, {type HttpRequestConfig} from 'luch-request'
import {reqInter} from "@/config/request/reqInter";
import {resInter} from "@/config/request/resInter";

const baseURL = import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL
const timeout = import.meta.env.VITE_REQUEST_TIMEOUT

/**
 * 请求实例化
 */
const instance = new Request({baseURL, timeout})

/**
 * 请求前拦截
 */
instance.interceptors.request.use(reqInter,
    error => {
        return Promise.reject(error)
    });


/**
 * 响应拦截
 */
instance.interceptors.response.use(resInter,
    error => {
        return Promise.reject(error);
    })

export default (config: HttpRequestConfig) => {
    return instance.middleware(config)
}
